<template>
  <div class="top">
    <transition name="slip-in-top">
      <div class="full-top" v-show="isHome" :style="topheight">
        <transition name="fade-fast">
          <Login v-show="isSign&&isHome" @login="login" @regist="regist"></Login>
        </transition>
        <transition name="fade">
          <div class="logo" v-show="isHome" @click="isSign=!isSign" :style="topmargin">
            <transition name="fade">
              <img src="../../assets/icon2.png" alt="" class="logoimg" v-show="!isSign">
            </transition>
            <transition name="fade">
              <img src="../../assets/x.png" alt="" class="logoimg" v-show="isSign">
            </transition>
          </div>
        </transition>

        <div class="title">
          Delivery Of Goods System
        </div>

        <div class="login" @click="isSign=true" v-show="!isSign">
          Sign In/ Sign Up
        </div>

      </div>
    </transition>
    <transition name="slip-in-top">
      <div class="mini-top" v-show="!isHome" @click="$router.push({path:'/'})">
        Log Out
      </div>
    </transition>
  </div>
</template>

<script>
  import Login from '../GDHeader/GDHeaderLogin'


  export default {
    name: "GDHeader",
    props: ['isHome'],
    components: {
      Login,
    },
    data() {
      return {
        isSign: false,
      }
    },
    methods: {
      login(user) {

        const data=this.api.login(user);
        if(data.error){
          this.$message({message:data.error,type:'warning'});
        }else{
          this.$store.commit('setUsername', data.data.username);
          this.$store.commit('setUser',data.data);
          this.isSign = false;
          this.$router.push({path: `/fun`});
        }

      },
      regist(user){
        const data=this.api.signup(user);
        if(data.error){
          this.$message({message:data.error,type:'warning'});
        }else{
          this.$store.commit('setUsername', data.data.username);
          this.$store.commit('setUser',data.data);
          this.isSign = false;
          this.$router.push({path: `/fun`});
        }
      }
    },
    computed: {
      topheight() {
        return (this.isSign ? 'height:500px' : 'height:60px')
      },
      topmargin() {
        return (this.isSign ? 'margin-top:460px;transform:rotate(720deg);' : 'margin-top:20px;transform:rotate(-720deg);')
      }
    },
    mounted() {
      this.bus.$on('signIn', () => {
        this.isSign = true;
      })
    }
  }
</script>

<style scoped>
  .title {
    position: absolute;
    left: 10px;
    top: 10px;
    font-weight: 600;
    /*font-size:18px;*/
    font-family: Arial;
    color: #bbbbbb;
  }

  .title:hover {
    color: white;
  }

  .login {
    /*font-size:18px;*/
    position: absolute;
    top: 0;
    right: 40px;
    height: 60px;
    width: 200px;
    line-height: 60px;
    text-align: center;
    color: #bbbbbb;
    cursor: pointer;
  }

  .login:hover {
    color: white;
  }

  .logo {
    background-color: #4e4e4e;
    border: 2px solid #fff;
    box-shadow: 0 0 20px #8d8d8d, inset 0 0 80px 5px #1c2533;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
    text-align: center;
    color: #fff;
    line-height: 80px;
    font-size: 60px;
    overflow: hidden;
    font-family: fantasy;
    text-shadow: 0 0 4px #000;
    cursor: pointer;
    transition: all 0.5s ease;
  }

  .logo:hover {
    background: #929292;
  }

  .logoimg {
    position: absolute;
    top: 8px;
    left: 10px;
  }
  .logoimg2 {
    position: absolute;
    top: 0px;
    left: 0px;
  }

  .full-top {
    position: fixed;
    left: 0;
    z-index: 1001;
    top: 0;
    width: 100%;
    /*text-shadow: 0 0 4px #fff;*/
    color: #fff;
    height: 60px;
    line-height: 40px;
    text-align: left;
    font-size: 16px;
    user-select: none;
    background: #1c2533;
    transition: all 0.5s ease;
  }

  .mini-top {
    color: #fff;
    text-shadow: 0 0 4px #fff;
    position: absolute;
    z-index: 1000;
    float: right;
    height: 60px;
    width: 180px;
    top: 15px;
    right: 40px;
    border-radius: 4px;
    background: rgba(49, 53, 71, 0.3);
    line-height: 60px;
    text-align: center;
    font-size: 16px;
    user-select: none;
    transition: all 0.5s;
    box-shadow: 0 1px 4px #525252;
    cursor: pointer;
  }

  .mini-top:hover {
    background: #1c2533;
  }

</style>
